<template>
  <el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancel" :visible.sync="dialog"
             title="学员信息"
             append-to-body width="30%">
    <div class="head-container">
      <el-input v-model="name" clearable placeholder="输入名称搜索" maxlength="10" style="width: 200px;"
                class="filter-item" @keyup.enter.native="init"/>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="init">搜索</el-button>
    </div>
    <el-table ref="table" v-loading="loading" :data="data" size="small" style="width: 100%;" border>
      <el-table-column type="selection" width="55"/>
      <el-table-column prop="name" label="姓名"/>
      <el-table-column prop="phone" label="手机号"/>
    </el-table>
    <el-pagination
      :total="total"
      :current-page="page + 1"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"/>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="okSelect">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import initData from '@/mixins/initData'

  export default {
    name: 'userSelect',
    mixins: [initData],
    data() {
      return {
        dialog: false,
        rStudent: 'r_student',
        name: '',
        student: []
      }
    },
    methods: {
      cancel() {
        this.dialog = false
      },
      beforeInit() {
        this.url = 'web/user/page-list'
        this.params = { page: this.page, size: this.size, roleCode: 'r_student', name: this.name }
        return true
      },
      okSelect() {
        const data = this.$refs.table.selection
        const userInfo = []
        for (let i = 0; i < data.length; i++) {
          const user={deptUserId:data[i].id,deptUserName:data[i].name}
          userInfo.push(user)
        }
        this.$emit('setUserInfo', userInfo)
        this.cancel()
      }
    }
  }
</script>

<style scoped>

</style>
